package mysql

import (
	"new-rent/newrentrpc/newrentrpc"

	"gorm.io/gorm"
)

// 用户

type User struct {
	gorm.Model
	Username string `gorm:"type:varchar(30);not null;comment:用户名"`
	Password string `gorm:"type:varchar(32);not null;comment:用户密码"`
}

// 房屋

type House struct {
	gorm.Model
	Name    string `gorm:"type:varchar(30);not null;comment:房屋名称"`
	Address string `gorm:"type:varchar(30);not null;comment:房屋地区"`
}

// 房屋添加

func (h *House) HouseAdd(db *gorm.DB) error {
	return db.Debug().Create(h).Error
}

// 房源详情

func (h *House) HouseShow(db *gorm.DB, id int64) error {
	return db.Debug().Where("id=?", id).Find(h).Error
}

// 房屋列表

func HouseList(db *gorm.DB, in *newrentrpc.HouseListRequest) []*newrentrpc.HouseList {
	var list []*newrentrpc.HouseList
	db.Debug().Model(&House{}).
		Select("houses.id as house_Id", "name", "address").
		Scopes(Paginate(int(in.Page), int(in.Size))).
		Find(&list)
	return list
}
